package com.example.shopping.goods;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.shopping.R;

import java.util.List;

public class TypeAdapter extends BaseAdapter {
    Context context;
    List<TypeBean.DataBean> data;
    int selPos=0;

    public void setSelPos(int selPos) {
        this.selPos = selPos;
        notifyDataSetChanged();
    }
    public  TypeAdapter(Context context, List<TypeBean.DataBean>data){
        this.context=context;
        this.data=data;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("ResourceAsColor")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView= LayoutInflater.from(context).inflate(R.layout.item_type,null);
        TextView tv=convertView.findViewById(R.id.item_type_tv);
        TextView line=convertView.findViewById(R.id.item_type_line);
       TypeBean.DataBean bean= data.get(position);
       tv.setText(bean.getName());
       if (selPos==position){
           tv.setTextColor(R.color.BLUE);
           line.setVisibility(View.VISIBLE);
           convertView.setBackgroundColor(Color.LTGRAY);
       }else {
           tv.setTextColor(R.color.black);
           line.setVisibility(View.INVISIBLE);
           convertView.setBackgroundColor(Color.rgb(200,200,200));
       }
        return convertView;
    }
}
